package com.vogue.supplymall.entmanagement.domain.dao.impl;

import javax.annotation.Resource;

import com.vogue.supplymall.common.domain.dto.LicenceShopSearchInfo;
import org.springframework.stereotype.Repository;

import com.vogue.supplymall.entmanagement.domain.dao.LicenceApplyDao;
import com.vogue.supplymall.entmanagement.domain.mapper.LicenceApplyMapper;
import com.vogue.supplymall.entmanagement.domain.model.LicenceApply;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The type Licence apply dao.
 */
@Repository("licenceApplyDao")
public class LicenceApplyDaoImpl extends BaseDaoImpl<LicenceApply, Long> implements LicenceApplyDao{
	@Resource
	private LicenceApplyMapper licenceApplyMapper;

	@Override
	public List<Map<String, Object>> findShopList(LicenceShopSearchInfo licenceShopSearchInfo) {
		return licenceApplyMapper.findShopList(licenceShopSearchInfo);
	}

	@Override
	public List<Map<String, Object>> findWarning(LicenceShopSearchInfo licenceShopSearchInfo) {
		return licenceApplyMapper.findWarning(licenceShopSearchInfo);
	}

	@Override
	public List<LicenceApply> findLABySyscodeid(Long syscodeId) {
		
		return licenceApplyMapper.findLABySyscodeid(syscodeId);
	}

	@Override
	public List<Map<String, Object>> findShopApply(Long shopid, Long syscodid, String matchid) {
		// TODO Auto-generated method stub
		String sql = "select la.id applyid, la.applytype, la.applystatue, la.scopeid sodid,"
				+ " lc.name sodname, lad.id detailid, lad.licencetypeid, lt.name licencetypename, "
				+ " lad.begindate, lad.enddate, lad.url,lad.applystatue dapplystatue "
				+ " from licence_apply_detail lad, licence_apply la , licence_type lt, licence_scopeofbusiness lc "
				+ " where lad.applyid = la.id and lad.licencetypeid = lt.id and la.scopeid = lc.id "
				+ " and la.applytype in (1,2) and la.disabledflag = 0 "
				+ " and (lad.shopid=#{shopid} or (lad.matchid=#{matchid} and lad.syscodeid=#{syscodid})) "
				+ " order by la.applytype, lt.seqnum";
		Map<String, Object> map = new HashMap<>();
		map.put("shopid", shopid);
		map.put("syscodid", syscodid);
		map.put("matchid", matchid);
		return this.query0(sql, map);
//		return licenceApplyMapper.findShopApply(shopid, syscodid, matchid);
	}
}
